/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import com.opensymphony.xwork2.ActionContext;
import java.math.BigInteger;
import java.util.Map;
import models.AccountBO;
import models.PageBO;
import myconfession.dao.AccountDAO;
import myconfession.dto.account.Account;
import myconfession.dto.page.Page;
import myconfession.utils.FacebookUtil;

/**
 *
 * @author Liem
 */
public class reviewFbAction {

    String pageId;
    String pagename;
    String error;

    public reviewFbAction() {
    }

    public String execute() throws Exception {

        Map session = ActionContext.getContext().getSession();
        String username = (String) session.get("USER");
        if (username != null) {
            Account acc = AccountBO.getAccountByUsername(username);
            Page page = PageBO.getPageById(new BigInteger(pageId));
            String result = FacebookUtil.printFBInfo(page.getFbPageId(), acc.getFbToken());
            if (result != null) {
                if (!result.equals("error")) {
                    session.put("FB", result);
                    pagename = page.getPagename();
                    return "success";
                } else {
                    error = "Your facebook page not exist or you do not have authorized";
                }
            }
        }
        return "fail";

    }

    public String getPageId() {
        return pageId;
    }

    public void setPageId(String pageId) {
        this.pageId = pageId;
    }

    public String getPagename() {
        return pagename;
    }

    public void setPagename(String pagename) {
        this.pagename = pagename;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    
}
